﻿namespace Hidistro.SaleSystem.Catalog
{
    using Hidistro.Core;
    using Hidistro.Core.Entities;
    using Hidistro.Entities;
    using Hidistro.Entities.Comments;
    using Hidistro.Entities.Commodities;
    using Hidistro.Entities.Promotions;
    using Hidistro.Membership.Context;
    using Hidistro.SqlDal.Comments;
    using Hidistro.SqlDal.Commodities;
    using Hidistro.SqlDal.Members;
    using Hidistro.SqlDal.Orders;
    using Hidistro.SqlDal.Promotions;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Runtime.InteropServices;

    public static class ProductBrowser
    {
        public static bool AddProductToFavorite(int productId, int userId)
        {
            FavoriteDao dao = new FavoriteDao();
            return (dao.ExistsProduct(productId, userId) || dao.AddProductToFavorite(productId, userId));
        }

        public static bool CheckHasCollect(int memberId, int productId)
        {
            return new FavoriteDao().CheckHasCollect(memberId, productId);
        }

        public static int DeleteFavorite(int favoriteId)
        {
            return new FavoriteDao().DeleteFavorite(favoriteId);
        }

        public static bool DeleteFavorites(string ids)
        {
            return new FavoriteDao().DeleteFavorites(ids);
        }

        public static DbQueryResult GetBatchBuyProducts(ProductQuery query)
        {
            return new ProductBrowseDao().GetBatchBuyProducts(query);
        }

        public static DataTable GetBrandProducts(int? brandId, int pageNumber, int maxNum, out int total)
        {
            return new ProductBrowseDao().GetBrandProducts(brandId, pageNumber, maxNum, out total);
        }
        public static DataTable GetJsProducts(int top, int cid, int level)
        {
            return new ProductBrowseDao().GetJsProducts(top, cid, level);
        }
        public static DataTable GetJsProductList(int pages, int cid, out int count)
        {
            return new ProductBrowseDao().GetJsProductList(pages, cid, out count);
        }
        public static DbQueryResult GetBrowseProductList(ProductBrowseQuery query)
        {
            return new ProductBrowseDao().GetBrowseProductList(query);
        }

        public static BundlingInfo GetBundlingInfo(int Bundlingid)
        {
            return new BundlingDao().GetBundlingInfo(Bundlingid);
        }

        public static List<BundlingItemInfo> GetBundlingItemsByID(int BundlingID)
        {
            return new BundlingDao().GetBundlingItemsByID(BundlingID);
        }

        public static DbQueryResult GetBundlingProductList(BundlingInfoQuery query)
        {
            return new BundlingDao().GetBundlingProducts(query);
        }

        public static DataTable GetCounDownProducList(int maxnum)
        {
            return new CountDownDao().GetCounDownProducList(maxnum);
        }

        public static CountDownInfo GetCountDownInfo(int productId)
        {
            return new CountDownDao().GetCountDownByProductId(productId);
        }

        public static CountDownInfo GetCountDownInfoByCountDownId(int countDownId)
        {
            return new CountDownDao().GetCountDownInfo(countDownId);
        }

        public static DbQueryResult GetCountDownProductList(ProductBrowseQuery query)
        {
            return new CountDownDao().GetCountDownProductList(query);
        }

        public static decimal GetCurrentPrice(int groupBuyId, int prodcutQuantity)
        {
            return new GroupBuyDao().GetCurrentPrice(groupBuyId, prodcutQuantity);
        }

        public static DataTable GetExpandAttributes(int productId)
        {
            return new SkuDao().GetExpandAttributes(productId);
        }

        public static DataTable GetFavorites()
        {
            return new FavoriteDao().GetFavorites();
        }

        public static DbQueryResult GetFavorites(string tags, Pagination page)
        {
            return new FavoriteDao().GetFavorites(HiContext.Current.User.UserId, tags, page);
        }

        public static GiftInfo GetGift(int giftId)
        {
            return new GiftDao().GetGiftDetails(giftId);
        }

        public static IList<GiftInfo> GetGifts(int maxnum)
        {
            return new GiftDao().GetGifts(maxnum);
        }

        public static GroupBuyInfo GetGroupBuy(int groupbuyId)
        {
            return new GroupBuyDao().GetGroupBuy(groupbuyId);
        }

        public static DataTable GetGroupBuyProducts(int? categoryId, string keywords, int page, int size, out int total, bool onlyUnFinished = true)
        {
            return new GroupBuyDao().GetGroupBuyProducts(categoryId, keywords, page, size, out total, onlyUnFinished);
        }

        public static DataTable GetGroupByProductList(int maxnum)
        {
            return new GroupBuyDao().GetGroupByProductList(maxnum);
        }

        public static DataSet GetGroupByProductList(ProductBrowseQuery query, out int count)
        {
            return new GroupBuyDao().GetGroupByProductList(query, out count);
        }

        public static DataTable GetHomeProduct(ClientType clientType)
        {
            return new HomeProductDao().GetHomeProducts(clientType);
        }

        public static int GetLineItemNumber(int productId)
        {
            return new LineItemDao().GetLineItemNumber(productId);
        }

        public static DbQueryResult GetLineItems(Pagination page, int productId)
        {
            return new LineItemDao().GetLineItems(page, productId);
        }

        public static DataTable GetLineItems(int productId, int maxNum)
        {
            return new LineItemDao().GetLineItems(productId, maxNum);
        }

        public static DbQueryResult GetOnlineGifts(GiftQuery page)
        {
            page.IsOnline = true;
            return new GiftDao().GetGifts(page);
        }

        public static IList<GiftInfo> GetOnlinePromotionGifts()
        {
            return new GiftDao().GetOnlinePromotionGifts();
        }

        public static int GetOrderCount(int groupBuyId)
        {
            return new GroupBuyDao().GetOrderCount(groupBuyId);
        }

        public static ProductBrowseInfo GetProductBrowseInfo(int productId, int? maxReviewNum, int? maxConsultationNum)
        {
            return new ProductBrowseDao().GetProductBrowseInfo(productId, maxReviewNum, maxConsultationNum);
        }
        public static DataTable GetProductReview(int productId)
        {
            return new ProductBrowseDao().GetProductReview(productId);
        }

        public static DbQueryResult GetProductConsultations(ProductConsultationAndReplyQuery page)
        {
            return new ProductConsultationDao().GetConsultationProducts(page);
        }

        public static DataSet GetProductConsultationsAndReplys(ProductConsultationAndReplyQuery query, out int total)
        {
            return new ProductConsultationDao().GetProductConsultationsAndReplys(query, out total);
        }

        public static GroupBuyInfo GetProductGroupBuyInfo(int productId)
        {
            return new GroupBuyDao().GetProductGroupBuyInfo(productId);
        }

        public static DbQueryResult GetProductReviews(ProductReviewQuery reviewQuery)
        {
            return new ProductReviewDao().GetProductReviews(reviewQuery);
        }

        public static DataTable GetProductReviews(int maxNum)
        {
            ProductReviewQuery reviewQuery = new ProductReviewQuery
            {
                PageIndex = 1,
                PageSize = maxNum
            };
            return (new ProductReviewDao().GetProductReviews(reviewQuery).Data as DataTable);
        }
        public static DataTable GetProductReviewsNew(int top)
        {
            ProductReviewQuery reviewQuery = new ProductReviewQuery
            {
                PageIndex = 1,
                PageSize = top
            };
            return new ProductReviewDao().GetProductReviewsNew(reviewQuery).Tables[0];
        }
        public static DataSet GetUersPL()
        {
            return new ProductReviewDao().GetUserPL();
        }

        public static DataTable GetProducts(int? topicId, int? categoryId, string keyWord, int feature, int pageNumber, int maxNum, out int total, string sort, string order)
        {
            return new ProductBrowseDao().GetProducts(topicId, categoryId, keyWord, feature, pageNumber, maxNum, out total, sort, order == "asc");
        }

        public static ProductInfo GetProductSimpleInfo(int productId)
        {
            return new ProductDao().GetProductDetails(productId);
        }

        public static DataTable GetSaleProductRanking(int? categoryId, int maxNum)
        {
            return new ProductBrowseDao().GetSaleProductRanking(categoryId, maxNum);
        }

        public static DataTable GetSkus(int productId)
        {
            return new SkuDao().GetSkus(productId);
        }

        public static DataTable GetSubjectList(SubjectListQuery query)
        {
            return new ProductBrowseDao().GetSubjectList(query);
        }
        public static DataTable GetSubjectListTop(SubjectListQuery query)
        {
            return new ProductBrowseDao().GetSubjectListTop(query);
        }

        public static DataTable GetTopicProducts(int topicid, int maxNum)
        {
            return new ProductBrowseDao().GetTopicProducts(topicid, maxNum);
        }

        public static DbQueryResult GetUnSaleProductList(ProductBrowseQuery query)
        {
            query.ProductSaleStatus = ProductSaleStatus.UnSale;
            return new ProductBrowseDao().GetBrowseProductList(query);
        }

        public static DataSet GetUserProductReviewsAndReplys(UserProductReviewAndReplyQuery query, out int total)
        {
            return new ProductReviewDao().GetUserProductReviewsAndReplys(query, out total);
        }

        public static int GetUserProductReviewsCount()
        {
            return new ProductReviewDao().GetUserProductReviewsCount();
        }

        public static DataTable GetVistiedProducts(IList<int> productIds)
        {
            return new ProductBrowseDao().GetVistiedProducts(productIds);
        }

        public static bool InsertProductConsultation(ProductConsultationInfo productConsultation)
        {
            Globals.EntityCoding(productConsultation, true);
            return new ProductConsultationDao().InsertProductConsultation(productConsultation);
        }

        public static bool InsertProductReview(ProductReviewInfo review)
        {
            Globals.EntityCoding(review, true);
            return new ProductReviewDao().InsertProductReview(review);
        }

        public static bool IsBuyProduct(int productId)
        {
            return new LineItemDao().IsBuyProduct(productId);
        }

        public static void LoadProductReview(int productId, out int buyNum, out int reviewNum)
        {
            buyNum = 0;
            reviewNum = 0;
            new ProductReviewDao().LoadProductReview(productId, HiContext.Current.User.UserId, out buyNum, out reviewNum);
        }

        public static int UpdateFavorite(int favoriteId, string tags, string remark)
        {
            return new FavoriteDao().UpdateFavorite(favoriteId, tags, remark);
        }
        public static DataTable GetJsProductsReviews(int ProductId)
        {
            return new ProductBrowseDao().GetJsProductsReviews(ProductId);
        }
        public static DataTable GetJsProductsForCategory(int top, int ProductId)
        {
            return new ProductBrowseDao().GetJsProductsForCategory(top, ProductId);
        }
        public static CategoryInfo GetProductCategory(int categoryId)
        {
            return new ProductBrowseDao().GetProductCategory(categoryId);
        }
        public static bool UserProductNotify(int productId, int userId, decimal price, string phone, string mail)
        {
            return new ProductDao().UserProductNotify(productId, userId, price, phone, mail);
        }
    }
}

